const path = require('path');
const CompressionPlugin = require('compression-webpack-plugin');

module.exports = {
  outputDir: 'dist',
  // 没有路由前缀时必须是"/"
  publicPath: process.env.VUE_APP_ROUTE_PATH_PRE,
  pages: {
    index: {
      entry: 'src/main.js',
      template: 'index.html',
      filename: 'index.html',
      chunks: ['chunk-vendors', 'chunk-common', 'index']
    }
  },
  productionSourceMap: false,
  devServer: {
    proxy: {
      '/api-admin': {
        ws: false,
        target: process.env.VUE_APP_API_PROXY_HOST,
        changeOrigin: true
      }
    }
  },
  configureWebpack: {
    optimization: {
      splitChunks: {
        cacheGroups: {
          vendors: {
            name: 'chunk-vendors',
            test: /[\\/]node_modules[\\/]/,
            priority: -10,
            chunks: 'initial'
          },
          common: {
            name: 'chunk-common',
            minChunks: 2,
            priority: -20,
            chunks: 'initial',
            reuseExistingChunk: true
          }
        }
      }
    },
    resolve: {
      alias: {
        '@s': path.join(__dirname, 'src/style')
      }
    },
    plugins: [
      new CompressionPlugin({
        test: /\.(css|(j|t)sx?)$/,
        threshold: 1024
      })
    ]
  }
};
